import { User,UpdateUserRequest,GetUserRequest, ListUsersRequest, DeleteUserRequest, GetVirtUserRequest, GetVirtUserResponse} from "@/types/proto/api/v1/user_service";
import { ListUsersResponse, UpdatePasswordRequest, CreateUserRequest,SetVirtUserRequest,SetVirtUserResponse } from "@/types/proto/api/v1/user_service";

import { HelloRequest, HelloReply } from "@/types/proto/api/v1/hello_service";
import { SignOutRequest, GetAuthStatusRequest} from "@/types/proto/api/v1/auth_service";
import { userServiceClient, authServiceClient} from "./grpcweb_auth";
import { helloServiceClient} from "./grpcweb_auth";
import { Empty } from "@/types/proto/google/protobuf/empty";
import {useUserStore} from "@/store/user"

export async function SayHello(data: HelloRequest): Promise<HelloReply> {
  try {  
      const store = useUserStore();
      return helloServiceClient.sayHello(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }
  
  export async function UpdateUser(data: UpdateUserRequest): Promise<User> {
    try {  
      return userServiceClient.updateUser(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }

  export async function UpdateVirt(data: UpdateUserRequest): Promise<User> {
    try {  
      return userServiceClient.updateVirt(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }

  export async function CreateUser(data: CreateUserRequest): Promise<User> {
    try {  
      return userServiceClient.createUser(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }

  export async function UpdatePassword(data: UpdatePasswordRequest): Promise<Empty> {
    try {  
      return userServiceClient.updatePassword(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }

  export async function GetUser(data: GetUserRequest): Promise<User> {
    try {  
      return userServiceClient.getUser(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }

  export async function ListUsers(data: ListUsersRequest): Promise<ListUsersResponse> {
    try {  
      return userServiceClient.listUsers(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }

  export async function CreateVirt(data: CreateUserRequest): Promise<User> {
    try {  
      return userServiceClient.createVirtUser(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }

  export async function DeleteVirt(data: DeleteUserRequest): Promise<Empty> {
    try {  
      return userServiceClient.deleteUser(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }

  export async function DeleteUser(data: DeleteUserRequest): Promise<Empty> {
    try {  
      return userServiceClient.deleteUser(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }

  export async function GetVirtUserAbility(data: GetVirtUserRequest): Promise<GetVirtUserResponse> {
    try {  
      return userServiceClient.getVirtUserAbility(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }

  export async function SetVirtUserAbility(data: SetVirtUserRequest): Promise<SetVirtUserResponse> {
    try {  
      return userServiceClient.setVirtUserAbility(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }

  export async function Whoami(): Promise<User> {
    try {  
      let data = GetAuthStatusRequest
      return authServiceClient.getAuthStatus(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }

  